﻿namespace Smart.ERP
{
    using Smart.Data.Helper;
    using Smart.Utils.Lib;
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Windows.Forms;

    public class CURRENCY
    {
        private bool m_Active;
        private string m_Currency_ID;
        private string m_CurrencyName;
        private double m_Exchange;

        public CURRENCY()
        {
            this.m_Currency_ID = "";
            this.m_CurrencyName = "";
            this.m_Exchange = 0.0;
            this.m_Active = true;
        }

        public CURRENCY(string Currency_ID, string CurrencyName, double Exchange, bool Active)
        {
            this.m_Currency_ID = Currency_ID;
            this.m_CurrencyName = CurrencyName;
            this.m_Exchange = Exchange;
            this.m_Active = Active;
        }

        public void AddCombo(ComboBox combo)
        {
            MyLib.TableToComboBox(combo, this.GetList(), "Currency_ID", "Exchange");
        }

        public void AddComboAll(ComboBox combo)
        {
            DataTable list = new DataTable();
            list = this.GetList();
            DataRow row = list.NewRow();
            row["CURRENCYID"] = "All";
            row["CURRENCYName"] = "Tất cả";
            list.Rows.InsertAt(row, 0);
            MyLib.TableToComboBox(combo, list, "CURRENCYName", "CURRENCYID");
        }

        public string Delete()
        {
            string[] myParams = new string[] { "@Currency_ID" };
            object[] myValues = new object[] { this.m_Currency_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CURRENCY_Delete", myParams, myValues);
        }

        public string Delete(string Currency_ID)
        {
            string[] myParams = new string[] { "@Currency_ID" };
            object[] myValues = new object[] { Currency_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CURRENCY_Delete", myParams, myValues);
        }

        public string Delete(SqlConnection myConnection, string Currency_ID)
        {
            string[] myParams = new string[] { "@Currency_ID" };
            object[] myValues = new object[] { Currency_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "CURRENCY_Delete", myParams, myValues);
        }

        public string Delete(SqlTransaction myTransaction, string Currency_ID)
        {
            string[] myParams = new string[] { "@Currency_ID" };
            object[] myValues = new object[] { Currency_ID };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "CURRENCY_Delete", myParams, myValues);
        }

        public bool Exist(string Currency_ID)
        {
            bool hasRows = false;
            string[] myParams = new string[] { "@Currency_ID" };
            object[] myValues = new object[] { Currency_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("CURRENCY_Get", myParams, myValues);
            if (reader != null)
            {
                hasRows = reader.HasRows;
                reader.Close();
                helper.Close();
                reader = null;
            }
            return hasRows;
        }

        public string Get(string Currency_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Currency_ID" };
            object[] myValues = new object[] { Currency_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader("CURRENCY_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Currency_ID = Convert.ToString(reader["Currency_ID"]);
                    this.m_CurrencyName = Convert.ToString(reader["CurrencyName"]);
                    this.m_Exchange = Convert.ToSingle(reader["Exchange"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlConnection myConnection, string Currency_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Currency_ID" };
            object[] myValues = new object[] { Currency_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myConnection, "CURRENCY_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Currency_ID = Convert.ToString(reader["Currency_ID"]);
                    this.m_CurrencyName = Convert.ToString(reader["CurrencyName"]);
                    this.m_Exchange = Convert.ToSingle(reader["Exchange"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public string Get(SqlTransaction myTransaction, string Currency_ID)
        {
            string str = "";
            string[] myParams = new string[] { "@Currency_ID" };
            object[] myValues = new object[] { Currency_ID };
            SqlHelper helper = new SqlHelper();
            SqlDataReader reader = helper.ExecuteReader(myTransaction, "CURRENCY_Get", myParams, myValues);
            if (reader != null)
            {
                while (reader.Read())
                {
                    this.m_Currency_ID = Convert.ToString(reader["Currency_ID"]);
                    this.m_CurrencyName = Convert.ToString(reader["CurrencyName"]);
                    this.m_Exchange = Convert.ToSingle(reader["Exchange"]);
                    this.m_Active = Convert.ToBoolean(reader["Active"]);
                    str = "OK";
                }
                reader.Close();
                helper.Close();
                reader = null;
            }
            return str;
        }

        public DataTable GetList()
        {
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteDataTable("CURRENCY_GetList");
        }

        public string Insert()
        {
            string[] myParams = new string[] { "@Currency_ID", "@CurrencyName", "@Exchange", "@Active" };
            object[] myValues = new object[] { this.m_Currency_ID, this.m_CurrencyName, this.m_Exchange, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CURRENCY_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction)
        {
            string[] myParams = new string[] { "@Currency_ID", "@CurrencyName", "@Exchange", "@Active" };
            object[] myValues = new object[] { this.m_Currency_ID, this.m_CurrencyName, this.m_Exchange, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "CURRENCY_Insert", myParams, myValues);
        }

        public string Insert(string Currency_ID, string CurrencyName, double Exchange, bool Active)
        {
            string[] myParams = new string[] { "@Currency_ID", "@CurrencyName", "@Exchange", "@Active" };
            object[] myValues = new object[] { Currency_ID, CurrencyName, Exchange, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CURRENCY_Insert", myParams, myValues);
        }

        public string Insert(SqlConnection myConnection, string Currency_ID, string CurrencyName, double Exchange, bool Active)
        {
            string[] myParams = new string[] { "@Currency_ID", "@CurrencyName", "@Exchange", "@Active" };
            object[] myValues = new object[] { Currency_ID, CurrencyName, Exchange, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "CURRENCY_Insert", myParams, myValues);
        }

        public string Insert(SqlTransaction myTransaction, string Currency_ID, string CurrencyName, double Exchange, bool Active)
        {
            string[] myParams = new string[] { "@Currency_ID", "@CurrencyName", "@Exchange", "@Active" };
            object[] myValues = new object[] { Currency_ID, CurrencyName, Exchange, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "CURRENCY_Insert", myParams, myValues);
        }

        public string NewID()
        {
            return SqlHelper.GenCode("CURRENCY", "CURRENCYID", "");
        }

        public string Update()
        {
            string[] myParams = new string[] { "@Currency_ID", "@CurrencyName", "@Exchange", "@Active" };
            object[] myValues = new object[] { this.m_Currency_ID, this.m_CurrencyName, this.m_Exchange, this.m_Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CURRENCY_Update", myParams, myValues);
        }

        public string Update(string Currency_ID, string CurrencyName, double Exchange, bool Active)
        {
            string[] myParams = new string[] { "@Currency_ID", "@CurrencyName", "@Exchange", "@Active" };
            object[] myValues = new object[] { Currency_ID, CurrencyName, Exchange, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery("CURRENCY_Update", myParams, myValues);
        }

        public string Update(SqlConnection myConnection, string Currency_ID, string CurrencyName, double Exchange, bool Active)
        {
            string[] myParams = new string[] { "@Currency_ID", "@CurrencyName", "@Exchange", "@Active" };
            object[] myValues = new object[] { Currency_ID, CurrencyName, Exchange, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myConnection, "CURRENCY_Update", myParams, myValues);
        }

        public string Update(SqlTransaction myTransaction, string Currency_ID, string CurrencyName, double Exchange, bool Active)
        {
            string[] myParams = new string[] { "@Currency_ID", "@CurrencyName", "@Exchange", "@Active" };
            object[] myValues = new object[] { Currency_ID, CurrencyName, Exchange, Active };
            SqlHelper helper = new SqlHelper();
            return helper.ExecuteNonQuery(myTransaction, "CURRENCY_Update", myParams, myValues);
        }

        public bool Active
        {
            get
            {
                return this.m_Active;
            }
            set
            {
                this.m_Active = value;
            }
        }

        public string Currency_ID
        {
            get
            {
                return this.m_Currency_ID;
            }
            set
            {
                this.m_Currency_ID = value;
            }
        }

        public string CurrencyName
        {
            get
            {
                return this.m_CurrencyName;
            }
            set
            {
                this.m_CurrencyName = value;
            }
        }

        public double Exchange
        {
            get
            {
                return this.m_Exchange;
            }
            set
            {
                this.m_Exchange = value;
            }
        }

        public string ProductName
        {
            get
            {
                return "Class CURRENCY";
            }
        }

        public string ProductVersion
        {
            get
            {
                return "1.0.0.0";
            }
        }
    }
}

